using System;
using Cinemachine;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.PlayerController
{
    [RequireComponent(typeof(CinemachineVirtualCamera))]
    public class PlayerSyncCamera : MonoBehaviour
    {
        public Camera syncCamera;
        private CinemachineVirtualCamera _virtualCamera;
        
        private void Awake()
        {
            _virtualCamera = GetComponent<CinemachineVirtualCamera>();
        }

        public void OnLateUpdate()
        {
            if (syncCamera == null) return;
            
            transform.position = syncCamera.transform.position;
            transform.rotation = syncCamera.transform.rotation;

            _virtualCamera.m_Lens.FieldOfView = syncCamera.fieldOfView;
            _virtualCamera.m_Lens.NearClipPlane = syncCamera.nearClipPlane;
            _virtualCamera.m_Lens.FarClipPlane = syncCamera.farClipPlane;
        }
    }
}